package us.icitap.commandcenter.ui.operator;

import java.util.List;


import com.vaadin.data.util.BeanItemContainer;
import us.icitap.commandcenter.business.ejb.persistence.Call;
import us.icitap.commandcenter.ui.custom.CustColumnGenerator;
import us.icitap.commandcenter.ui.custom.CustTable;

public class CallList extends CustTable{


	private  final BeanItemContainer<Call> beans = new BeanItemContainer<Call>(Call.class);
	
	public CallList() {
		this.setContainerDataSource(beans);
	
		this.setVisibleColumns(new Object[]{"caller", "recordDate","callReason", "address", "description", "actualGrade", "mainDispatcher"});
		this.setColumnHeaders(new String[]{"TELEFONUESI","DT. REGJ.",  "ARSYEJA E TELEFONATES", "ADRESA", "PERSHKRIMI", "GRADA", "ZONA E MBULIMIT"});
		this.addGeneratedColumn("callReason", CustColumnGenerator.callReasonColumnGenerator);
		this.addGeneratedColumn("actualGrade", CustColumnGenerator.gradeColumnGenerator);
		this.addGeneratedColumn("mainDispatcher", CustColumnGenerator.dispatcherColumnGenerator);
		this.setPageLength(20);
		this.setWidth("100%");
		this.setColumnWidth("callReason", 100);
		this.setColumnWidth("address", 200);
		this.setColumnWidth("description", 200);
	
		this.updateTable();
	}
	
	

	public void updateTable(){
	
		boolean[] order = {false};
		this.sort(new Object[]{"recordDate"}, order);
		this.setCaption("Totali i telefonatave: " + this.getContainerDataSource().size());
	}

	public void addCallToTable(List<Call> callList){
		beans.addAll(callList);
		this.updateTable();
	}
	
	public void addNewCall(Call call){
		beans.addBean(call);
		this.updateTable();
	}
	
}
